package cn.virens.server.aio.listener.simple;

import cn.virens.common.RingByteBuffer;
import cn.virens.server.aio.listener.AioDataDecoder;
import cn.virens.server.aio.packet.AioReadPacket;
import cn.virens.server.common.ReadPacket;

public class SimpleAioDataDecoder implements AioDataDecoder {

	@Override
	public ReadPacket decode(RingByteBuffer buffer) {
		if (buffer.length() <= 5) return null;

		byte[] bs = new byte[buffer.length()];
		for (int i = 0; i < bs.length; i++) {
			bs[i] = buffer.read();
		}

		AioReadPacket packet = new AioReadPacket();
		packet.setData(bs);

		return packet;
	}

}
